<?php

/**
 * 餐厅编辑post
 * 
 * @copyright xinwei
 * @since 2012-04-17
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	
	cgi::both($g_cgival["id"], "id", 0);
	$g_cgival["id"] = intval($g_cgival["id"]);
	cgi::both($g_cgival["show_type"], "show_type", 0);
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["topic_id"], "topic_id", 0);
	$g_cgival["topic_id"] = string::un_html($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["tag_name"], "tag_name", "");
	$g_cgival["tag_name"] = string::un_html($g_cgival["tag_name"]);
	
	cgi::both($g_cgival["status"], "status", "");
	$g_cgival["status"] = string::un_html($g_cgival["status"]);
	
	cgi::both($g_cgival["type"], "type", "edit");
	$g_cgival["type"] = string::un_html($g_cgival["type"]);
	
	cgi::both($g_cgival["desc"], "desc", "");
	//$g_cgival["desc"] = string::un_html($g_cgival["desc"]);
	
	cgi::both($g_cgival["black_word"], "black_word", "");
	//$g_cgival["black_word"] = string::un_html($g_cgival["black_word"]);
	
	cgi::both($g_cgival["need_cron"], "need_cron", 1);
	$g_cgival["need_cron"] = string::un_html($g_cgival["need_cron"]);
	


}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	
	$topic_id = $g_cgival["topic_id"];
	$tag_name = $g_cgival["tag_name"];
	$id= $g_cgival["id"];
	$desc = $g_cgival["desc"];
	$black_word =  $g_cgival["black_word"];
	
	if(!$topic_id  || $topic_id == 900)
	{
		throw new Exception("请选择站点！");
	}
	
	$uid = admin::admin_get_login_uid();
	$nickname = admin::admin_get_login_user_name();
	
	
	$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();	
	if($id)
	{
		if($g_cgival["type"] == "del")
		{
			$db_mblog_cron_topic_tag->admin_update_mblog_cron_topic_tag($id,"",0);
		}
		else
		{
			$db_mblog_cron_topic_tag->admin_update_mblog_cron_topic_tag($id,$topic_id,$g_cgival["status"],$tag_name,$desc,$black_word);	
		}
		
	}
	else
	{
		$db_mblog_cron_topic_tag->admin_insert_mblog_cron_topic_tag($topic_id,$uid,$nickname,$tag_name,$desc,$black_word);
		
	}
	

}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
	{
		print_r($g_show);
		exit;
	}
	
	
	echo json_encode($g_show);
}

